package com.itheima.dao;

import com.itheima.Member;
import com.itheima.Orders;
import com.itheima.Product;
import com.itheima.Traveller;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface IOrdersDao {

    @Select("select * from orders")
    @Results(id = "ordersMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),

            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(property = "product", column = "productId", javaType = Product.class,
                    one = @One(select = "com.itheima.dao.IProductDao.findById")),
            @Result(property = "traveller", column = "travellerId", javaType = Traveller.class,
                    many = @Many(select = "com.itheima.dao.ITravellerDao.findByOrdersId")),
            @Result(property = "member", column = "memberId", javaType = Member.class,
                    one = @One(select = "com.itheima.dao.IMemberDao.findByMemberId"))})
    /**
     * 查询所有订单
     */
    public List<Orders> findAll();

    @ResultMap("ordersMap")
    @Select("select * from orders where id = #{ordersId}")
    /**
     * 根据id查询订单详情
     */
    public Orders findById(String ordersId);

}

